package com.mason.forum.config;

import com.mason.forum.component.UserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-10-06
 * Time: 12:56
 */
@Configuration//不是Configurable！
public class UserLoginConfig implements WebMvcConfigurer {

    @Resource
    private UserInterceptor userInterceptor;//自定义的登录拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userInterceptor)
                .addPathPatterns("/**")
                //以下是不需要进行拦截的swagger路径：===================
                .excludePathPatterns("/swagger-ui/**")
                .excludePathPatterns("/swagger-ui.html")
                .excludePathPatterns("/configuration/ui/**")
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/configuration/security/**")
                .excludePathPatterns("/v2/api-docs/**")
                .excludePathPatterns("/v3/api-docs/**")
                .excludePathPatterns("/error/**")
                .excludePathPatterns("/webjars/**")
                // 静态资源：========================================
                .excludePathPatterns("/dist/**")
                .excludePathPatterns("/image/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/load/**")
                .excludePathPatterns("/**.pdf")
                // 页面全部开放，调用接口才触发跳转~
                // 我觉得页面访问没啥关系，主要是重要的接口！
                .excludePathPatterns("/article.html")
                .excludePathPatterns("/article_edit.html")
                .excludePathPatterns("/article_list.html")
                .excludePathPatterns("/details.html")
                .excludePathPatterns("/index.html")
                .excludePathPatterns("/profile.html")
                .excludePathPatterns("/settings.html")
                .excludePathPatterns("/sign-in.html")
                .excludePathPatterns("/sign-up.html")
                .excludePathPatterns("/Soars.png")
                // 接口：===========================================
                    // 1. user:
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/login")
//                .excludePathPatterns("/user/info")
//                .excludePathPatterns("/user/logout")
//                .excludePathPatterns("/user/update")
//                .excludePathPatterns("/user/password")
                    // 2. board:
//                .excludePathPatterns("/board/list")
//                .excludePathPatterns("/board/search")
                    // 3. article:
//                .excludePathPatterns("/article/create")
//                .excludePathPatterns("/article/list")
//                .excludePathPatterns("/article/detail")
//                .excludePathPatterns("/article/modify")
//                .excludePathPatterns("/article/like")
//                .excludePathPatterns("/article/delete")
//                .excludePathPatterns("/article/catalog")
                    // 4. reply:
//                .excludePathPatterns("/reply/create")
//                .excludePathPatterns("/reply/list")
                    // 5. message:
//                .excludePathPatterns("/message/send")
//                .excludePathPatterns("/message/count")
//                .excludePathPatterns("/message/list")
//                .excludePathPatterns("/message/read")

        ;
    }


}
